/**
 * User: alesj
 * Date: 2005.6.1
 * Time: 15:33:28
 * 
 * (C) Genera Lynx d.o.o.
 */

package com.alesj.newsfeed.data;

import com.generalynx.common.constants.WebConst;
import com.generalynx.common.data.ADEData;
import com.generalynx.ecos.data.Address;
import com.generalynx.ecos.data.CreatorComponent;
import com.generalynx.ecos.data.User;
import com.generalynx.ecos.data.types.Status;
import com.generalynx.ecos.utils.Context;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Set;

public abstract class Contact extends ADEData implements Tokenizable, Serializable {

    private static final long serialVersionUID = 1L;

    private int id;
    private String m_telephone;
    private String m_gsm;
    private String m_email;
    private Address address;
    private CreatorComponent creator;
    private Status m_status;
    private Set messages;
    private Set entries;
    private String m_remark;

    protected String nonActiveLabel() {
        if (Status.DELETED.equals(getStatus())) {
            return " [X]";
        } else if (Status.DISABLED.equals(getStatus())) {
            return " [D]";
        } else {
            return "";
        }
    }

    protected String getSelectAction() {
        return "contactEntrySelect";
    }

    public void beforeBind() {
        setAddress(new Address());
    }

    public void beforeInsert(Context context) {
        setCreator(new CreatorComponent());
        User creator = (User)context.getAttribute(WebConst.USER);
        getCreator().setCreatorId(creator.getId());
        getCreator().setCreationTime(new Date());
    }

    /**
     * Printed in message.jsp.
     */
    public String getMessageLabel() {
        return getLabel() + " (" + getEmail() + ")";
    }

    public List getTokens() {
        String street = null;
        String city = null;
        String post = null;
        if (getAddress() != null) {
            street = getAddress().getStreet();
            city = getAddress().getCity();
            post = getAddress().getPost();
        }
        return Arrays.asList(
                getTelephone(),
                getGsm(),
                getEmail(),
                street,
                city,
                post,
                getStatus()
        );
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTelephone() {
        return m_telephone;
    }

    public String getGsm() {
        return m_gsm;
    }

    public void setGsm(String gsm) {
        m_gsm = gsm;
    }

    public void setTelephone(String telephone) {
        m_telephone = telephone;
    }

    public String getEmail() {
        return m_email;
    }

    public void setEmail(String email) {
        m_email = email;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public CreatorComponent getCreator() {
        return creator;
    }

    public void setCreator(CreatorComponent creator) {
        this.creator = creator;
    }

    public Status getStatus() {
        return m_status;
    }

    public void setStatus(Status status) {
        m_status = status;
    }

    public Set getMessages() {
        return messages;
    }

    public void setMessages(Set messages) {
        this.messages = messages;
    }

    public Set getEntries() {
        return entries;
    }

    public void setEntries(Set entries) {
        this.entries = entries;
    }

    public String getRemark() {
        return m_remark;
    }

    public void setRemark(String remark) {
        m_remark = remark;
    }

}
